package offer;

public class offer_0053_1 {
    public int search(int[] nums, int target) {
        int len=nums.length;
        if(len==0) return 0;
        int index=search(0,len-1,nums,target);
        if(index==-1) return 0;
        int sum=1;
        for(int i=1;index+i<len;++i){
            if(nums[index+i]!=target) break;
            sum++;
        }
        for(int i=1;index-i>=0;++i){
            if(nums[index-i]!=target) break;
            sum++;
        }
        return sum;
    }
    public int search(int left,int right,int[] nums,int target){

        int mid=(right-left)/2+left;
        if(nums[mid]==target) return mid;
        if(left==right) return -1;
        if(nums[mid]<target) return search(mid+1,right,nums,target);
        return search(left,mid,nums,target);
    }
}
